package dateStructure;

import java.util.Scanner;

public class listStack {
    private stack S;//定义一个老的头结点
    private class stack{
        int date;
        stack next;
    }
    private listStack(){
        S=null;//在构造器里初始化
    }
    private boolean push(int date) {
        stack p=new stack();
        p.date=date;
        p.next = S;
        S = p;
        return true;
    }
    private boolean pop() {
        if(S==null){
            System.out.println("栈已空！");
            return false;
        }
        stack p=new stack();
        p = S;
        S = S.next;
        return true;
    }
    public int getElem(){
        if(S!=null){
            return S.date;
        }
        return -1;
    }
    public static void main(String[] args) {
        listStack s=new listStack();
        Scanner scanner=new Scanner(System.in);
        System.out.print("请输入元素的个数：");
        int n=scanner.nextInt();
        int sum=n;
        while (sum-->0){
            s.push(scanner.nextInt());
        }
        while (n-->0){
            System.out.println("弹出栈顶元素为："+s.getElem());
            s.pop();
        }
    }
}

